#ifndef _YMODEM_H_
#define _YMODEM_H_
#include "sys_hc32f460.h"
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
#include <stdbool.h>

#define PACKET_HEADER           (3)
#define PACKET_SIZE             (128)
#define PACKET_1K_SIZE          (1024)

#define STEP_START				0x00
#define STEP_HAND_SHAKE			0X01
#define STEP_HAND_DONE			0X02
#define STEP_PACK_DATA			0x03
#define STEP_EOT_ONE			0X04
#define STEP_EOT_TWO			0X05
#define STEP_FINISH				0x06
#define STEP_FINISHED			0x07
#define STEP_ERROR				0x0F

#define FILE_NAME_LENGTH        (128)
#define FILE_SIZE_LENGTH        (16)

#define SOH                     (0x01)  /* start of 128-byte data packet */
#define STX                     (0x02)  /* start of 1024-byte data packet */
#define EOT                     (0x04)  /* end of transmission */
#define ACK                     (0x06)  /* acknowledge */
#define NAK                     (0x15)  /* negative acknowledge */
#define CA                      (0x18)  /* two of these in succession aborts transfer */
#define CRC16                   (0x43)  /* 'C' == 0x43, request 16-bit CRC */

#define CRC_ERR					(0x44)

#define ABORT1                  (0x41)  /* 'A' == 0x41, abort by user */
#define ABORT2                  (0x61)  /* 'a' == 0x61, abort by user */

typedef struct{
	uint8_t step;
	uint16_t total_pack_num;
	uint32_t iap_size;
	uint32_t iap_addr_offset;
	uint32_t remain_size;
	uint16_t recv_pack_num;
	uint8_t fileName[FILE_NAME_LENGTH];
	uint8_t timeout_cnt;
	uint8_t recv_data_flag;
}YmodemCtrlData_t;

void ymodem_update_process(void);

#endif  /* _YMODEM_H_ */
